﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Kinect;
using System.Windows;
using System.Collections;

namespace GestureSaver
{
    [Serializable]
    public class MPosition
    {
        public float X { get; set; }
        public float Y { get; set; }
        public float Z { get; set; }
    }

    [Serializable]
    public class MJoint
    {
        public JointType JointType { get; set; }
        public MPosition Position { get; set; }

        public MJoint()
        {
            this.Position = new MPosition();
        }
    }

    [Serializable]
    public class MSkeleton : IEnumerable
    {
        public TimeSpan timeDifference;
        private Dictionary<JointType, MJoint> data;

        public MSkeleton()
        {
            this.data = new Dictionary<JointType, MJoint>();
            
            foreach (JointType type in Enum.GetValues(typeof(JointType)))
            {
                data.Add(type, new MJoint() { JointType = type });
            }
        }

        public MJoint this[JointType jointType]
        {
            get
            {
                return data[jointType];
            }
            set
            {
                data[jointType] = value;
            }
        }

        public IEnumerator GetEnumerator()
        {
            return new MSkeletonEnumerator(this);
        }

        private class MSkeletonEnumerator : IEnumerator
        {
            int position = -1;
            private MSkeleton instance;
            
            public MSkeletonEnumerator(MSkeleton inst)
            {
                this.instance = inst;
            }

            public object Current
            {
                get
                {
                    try
                    {
                        return instance.data[(JointType)position];
                    }
                    catch (IndexOutOfRangeException)
                    {
                        throw new InvalidOperationException();
                    }
                }
            }

            public bool MoveNext()
            {
                position++;
                return (position < instance.data.Count);
            }

            public void Reset()
            {
                position = -1;
            }
        }
    }
}
